package cn.lx.init;

import cn.lx.pojo.TlIndex;
import cn.lx.service.IndexService;
import cn.lx.service.LikeSearch;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @author lixin
 */
@Component
public class MyInit implements CommandLineRunner, ApplicationContextAware {

    @Autowired
    IndexService indexService;
    ApplicationContext applicationContext;
    public static LikeSearch<String> likeSearch = new LikeSearch<String>();

    @Override
    public void run(String... strings) throws Exception {
        List<TlIndex> all = indexService.all();
        for (TlIndex index : all) {
            likeSearch.put(index.getCompany_name(), index.getCompany_name() + index.getId());
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
